home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / DefineSprite_41_mc_rabbi / frame_1 / DoAction.as
Encoding:
Text File  |  2011-01-06  |  7.6 KB  |  397 lines

  1. if(!init)
  2. {
  3.    orig_scale = _xscale;
  4.    hitarea._visible = false;
  5.    walking = false;
  6.    parrying = false;
  7.    attacking = false;
  8.    jumping = false;
  9.    fall_distance = 0;
  10.    init = true;
  11.    side = "L";
  12.    lastdecision = 0;
  13.    deadcount = 0;
  14.    floor = 62;
  15.    walkdistance = 24;
  16.    reach = 32;
  17.    spell_reach = 200;
  18.    damage = 4;
  19.    total_ki = 10;
  20.    ki = total_ki;
  21.    spell_ki_cost = 9;
  22.    kick_ki_cost = 3;
  23.    pushfactor = 6;
  24.    total_hp = 50;
  25.    hp = total_hp;
  26.    regen_rate = 0.05;
  27.    score = 200;
  28.    _root.createPic("pic_rabbi",this);
  29. }
  30. attacking = false;
  31. speed = 0;
  32. walking = false;
  33. this.onEnterFrame = function()
  34. {
  35.    if(!init)
  36.    {
  37.       return undefined;
  38.    }
  39.    if(dead)
  40.    {
  41.       deadcount++;
  42.       if(deadcount > 1000)
  43.       {
  44.          trace("unloading:" + this);
  45.          this.removeMovieClip();
  46.          unloadMovie(this);
  47.       }
  48.       gotoAndStop("die");
  49.       this._x -= _hitomi.speed;
  50.       return undefined;
  51.    }
  52.    lastdecision++;
  53.    onDie();
  54.    onWalk();
  55.    doCalcs();
  56.    var _loc3_ = fallback();
  57.    if(_loc3_ == undefined)
  58.    {
  59.       _loc3_ = 0;
  60.    }
  61.    var _loc4_ = _root.hitomi.speed;
  62.    checkHits();
  63.    decide();
  64.    this._x -= _loc4_;
  65.    this._x += _loc3_;
  66.    if(!walking && !attacking && !turning && !recieving)
  67.    {
  68.       unwalk();
  69.       gotoAndStop("stand");
  70.    }
  71. };
  72. checkHits = function()
  73. {
  74.    if(this.hitarea.hitTest(_hitomi.hitarea))
  75.    {
  76.       onHit();
  77.    }
  78.    if(_root.hitomi.hitTest(_X + club._x * getDirection(),_Y + club._y,true))
  79.    {
  80.       _root.hitomi.recieveHit(this);
  81.    }
  82.    if(_root.hitomi.hitTest(_X + (club._x + 3) * getDirection(),_Y + club._y,true))
  83.    {
  84.       _root.hitomi.recieveHit(this);
  85.    }
  86.    if(_root.hitomi.hitTest(_X + (club._x - 3) * getDirection(),_Y + club._y,true))
  87.    {
  88.       _root.hitomi.recieveHit(this);
  89.    }
  90. };
  91. doCalcs = function()
  92. {
  93.    if(!(slashing || jumping || parrying || turning || recieving))
  94.    {
  95.       ki += regen_rate;
  96.    }
  97.    if(ki > total_ki)
  98.    {
  99.       ki = total_ki;
  100.    }
  101.    if(hp > total_hp)
  102.    {
  103.       hp = total_hp;
  104.    }
  105.    if(ki < 0)
  106.    {
  107.       ki = 0;
  108.    }
  109.    if(hp < 1)
  110.    {
  111.       hp = 0;
  112.       die();
  113.    }
  114.    pic.bars.hp._xscale = Math.ceil(hp / total_hp * 100);
  115.    pic.bars.ki._xscale = Math.ceil(ki / total_ki * 100);
  116. };
  117. getDirection = function()
  118. {
  119.    if(orig_scale == _xscale)
  120.    {
  121.       return 1;
  122.    }
  123.    return -1;
  124. };
  125. bombHit = function(hit_by, dmg, pushf)
  126. {
  127.    hp -= dmg;
  128. };
  129. onHit = function()
  130. {
  131.    _root.hitcount = _root.hitcount + 1;
  132.    if(_root.hitcount > 1000)
  133.    {
  134.       _root.hitcount = 0;
  135.    }
  136.    hp -= _hitomi.damage;
  137.    _root._score += _hitomi.damage;
  138.    var _loc3_ = _root.attachMovie("mc_blood01","blood" + hitcount,3100 + hitcount);
  139.    _loc3_._rotation = random(360);
  140.    var _loc4_ = random(150) + 100;
  141.    _loc3_._xscale = _loc4_;
  142.    _loc3_._yscale = _loc4_;
  143.    if(_hitomi.side == "R")
  144.    {
  145.       _loc3_._x = _hitomi._x + _hitomi.hitarea._x;
  146.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  147.    }
  148.    else
  149.    {
  150.       _loc3_._x = _hitomi._x - _hitomi.hitarea._x;
  151.       _loc3_._y = _hitomi._y + _hitomi.hitarea._y;
  152.    }
  153.    fall_distance = _hitomi.pushback * 2;
  154.    fallback = function()
  155.    {
  156.       fall_distance--;
  157.       if(fall_distance < 1)
  158.       {
  159.          delete this.fallback;
  160.          fall_distance = 0;
  161.          return 0;
  162.       }
  163.       return _hitomi.getDirection() * (fall_distance / 2);
  164.    };
  165.    soundsList = ["loud_metal_hit","blow01","beat","cabasa","zddd1kick1","zddd1kick2","zddd1tamb"];
  166.    playSound(soundsList);
  167. };
  168. die = function()
  169. {
  170.    _root.removePic(pic);
  171.    dead = true;
  172.    walking = false;
  173.    slashing = false;
  174.    attacking = false;
  175.    speed = 0;
  176.    gotoAndStop("die");
  177.    play();
  178. };
  179. decide = function()
  180. {
  181.    if(dead)
  182.    {
  183.       return undefined;
  184.    }
  185.    if(!walking && !attacking || lastdecision > 70)
  186.    {
  187.       walking = false;
  188.       parrying = false;
  189.       attacking = false;
  190.       lastdecision = 0;
  191.       var _loc2_ = random(20);
  192.       if(_loc2_ == 0)
  193.       {
  194.          walk_distance = random(walkdistance) + 6;
  195.          walk();
  196.          return undefined;
  197.       }
  198.       var _loc1_ = Math.abs(_hitomi._x - _X);
  199.       if(_loc2_ < 3)
  200.       {
  201.          if(_loc1_ < 10 || _loc1_ > reach)
  202.          {
  203.             if(_hitomi._x < _X)
  204.             {
  205.                left();
  206.             }
  207.             else
  208.             {
  209.                right();
  210.             }
  211.             return undefined;
  212.          }
  213.       }
  214.       if(_loc1_ < reach)
  215.       {
  216.          if(_hitomi._x > _X && side == "L")
  217.          {
  218.             turn("R");
  219.          }
  220.          if(_hitomi._x < _X && side == "R")
  221.          {
  222.             turn("L");
  223.          }
  224.          attack();
  225.          return undefined;
  226.       }
  227.       if(_loc1_ < spell_reach)
  228.       {
  229.          if(_hitomi._x > _X && side == "L")
  230.          {
  231.             turn("R");
  232.          }
  233.          if(_hitomi._x < _X && side == "R")
  234.          {
  235.             turn("L");
  236.          }
  237.          spell();
  238.          return undefined;
  239.       }
  240.       unwalk();
  241.       gotoAndStop("stand");
  242.    }
  243. };
  244. attack = function()
  245. {
  246.    if(ki < kick_ki_cost)
  247.    {
  248.       walking = false;
  249.       walk_distance = random(walkdistance) + 6;
  250.       walk();
  251.       return undefined;
  252.    }
  253.    if(!attacking)
  254.    {
  255.       ki -= kick_ki_cost;
  256.       walking = false;
  257.       speed = 0;
  258.       attacking = true;
  259.       gotoAndStop("hit");
  260.       play();
  261.    }
  262. };
  263. spell = function()
  264. {
  265.    if(ki < spell_ki_cost)
  266.    {
  267.       walking = false;
  268.       speed = 0;
  269.       walk_distance = random(walkdistance) + 4;
  270.       walk();
  271.       return undefined;
  272.    }
  273.    if(!attacking)
  274.    {
  275.       ki -= spell_ki_cost;
  276.       walking = false;
  277.       speed = 0;
  278.       attacking = true;
  279.       gotoAndStop("spell");
  280.       play();
  281.    }
  282. };
  283. throwSpell = function()
  284. {
  285.    var _loc3_ = _root.attachMovie("mc_spell","spell" + random(10),4000 + random(100));
  286.    _loc3_.caster = this;
  287. };
  288. unjump = false;
  289. if(!init)
  290. {
  291.    side = "L";
  292.    orig_scale = _xscale;
  293.    init = true;
  294. }
  295. slash1 = function()
  296. {
  297.    if(jumping || slashing)
  298.    {
  299.       return undefined;
  300.    }
  301.    slashing = true;
  302.    gotoAndStop("hit");
  303.    play();
  304. };
  305. right = function()
  306. {
  307.    turn("R");
  308. };
  309. left = function()
  310. {
  311.    turn("L");
  312. };
  313. turn = function(sideto)
  314. {
  315.    if(!sideto)
  316.    {
  317.       if(side == "L")
  318.       {
  319.          sideto = "R";
  320.       }
  321.       else
  322.       {
  323.          sideto = "L";
  324.       }
  325.    }
  326.    if(side != sideto)
  327.    {
  328.       if(!jumping)
  329.       {
  330.          turnTo = sideto;
  331.          walking = false;
  332.          jumping = false;
  333.          parrying = false;
  334.          if(sideto == "L")
  335.          {
  336.             _xscale = orig_scale;
  337.          }
  338.          else
  339.          {
  340.             _xscale = - orig_scale;
  341.          }
  342.          side = sideto;
  343.       }
  344.    }
  345.    else
  346.    {
  347.       turning = false;
  348.       walk_distance = random(walkdistance) + 6;
  349.       walk();
  350.    }
  351. };
  352. walk = function()
  353. {
  354.    if(walking || attacking || parrying || turning || dead)
  355.    {
  356.       trace("abort walk");
  357.       return undefined;
  358.    }
  359.    walking = true;
  360.    gotoAndStop("walk");
  361.    play();
  362.    this.count = 0;
  363.    this.onWalk = function()
  364.    {
  365.       count++;
  366.       walking = true;
  367.       if(side == "R")
  368.       {
  369.          _X = _X + 1.5;
  370.       }
  371.       else
  372.       {
  373.          _X = _X - 1.5;
  374.       }
  375.       if(count > Math.abs(walk_distance))
  376.       {
  377.          delete this.onWalk;
  378.          walking = false;
  379.          unwalk();
  380.       }
  381.    };
  382. };
  383. unwalk = function()
  384. {
  385.    if(walking && !dead)
  386.    {
  387.       walking = false;
  388.       speed = 0;
  389.       gotoAndStop("stand");
  390.    }
  391. };
  392. playSound = function(ids)
  393. {
  394.    _root.sounds.playSound(ids);
  395. };
  396. stop();
  397.